package com.test.practice.exception;

import java.io.IOException;

/**
 * MyExceptionDemo1--Practice
 * 通过throwable cause属性或者
 * initCause()方法来存放接收casue，用来保存最原始的异常信息
 *
 * @author: Jovi
 * @createTime: 2018-02-27 16:57
 **/
public class MyExceptionDemo1 {

    public void m3() throws MyException {
        throw new MyException("异常深度3");
    }

    public void m2() throws Exception {
        try {
            m3();
        } catch (MyException e) {
            //通过throwable cause属性来存放cause
            throw new MyException("异常深度2", e);
        }
    }

    public void m1() throws IOException {
        try {
            m2();
        } catch (Exception e) {
            IOException io = new IOException("异常深度1");
            //通过initCause方法来存放cause
            io.initCause(e);
            throw io;
        }
    }

    public static void main(String[] args) {
        try {
            new MyExceptionDemo1().m1();
        } catch (IOException e) {
            //打印异常堆栈信息
            e.printStackTrace();
        }
    }
}
